<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>选择图片测试</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>

</head>

<body>

    <button onclick="uploadImg()">点击上传图片</button>
    <input id="file1" type="file" onchange="change()" />
</body>

</html>


<script>

    function change(e){
        console.log(file1.files)

    }

    function uploadImg(){
        console.log('调用')
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                var localIds = res.localIds; //图片的本地id，微信生成的

                wx.uploadImage({
                    localId: localIds[0], // 需要上传的图片的本地ID，由chooseImage接口获得
                    success: function (res) {
                        var serverId = res.serverId; // 返回图片的服务器端ID
                    }
                });


            }
        });

    }

</script>
